package indi.gao.leetcode.problem;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Description:</p>
 * <p>person: gaolei</p>
 * <P>Created Date :2020$-04$-01$</P>
 */
public class TwoSum2632 {
    public static void main(String[] args) {
        int nums[] = new int[]{1, 2, 3, 4, 5, 6};
        int target = 11;
        System.out.println(Arrays.toString(new Solution2632().twoSum(nums, target)));
    }
}

class Solution2632 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int another = target - nums[i];
            if (map.containsKey(another)) {
                return new int[]{i, map.get(another)};
            } else {
                map.put(nums[i], i);
            }
        }
        return null;
    }
}